import { isiOS } from '@/utils';

export default function useInput() {
  function stopMove(e: Event) {
    console.log('stopMove');
    e.preventDefault();
  }
  
  function focusin(e: any) {
    console.log('focusIn');
    e.target.scrollIntoView({
      behavior: "smooth",
      block: "end"
    });
    if (isiOS) {
      scrollTo(0, 0);
      document.addEventListener('touchmove', stopMove, {
        passive: false,
      })
    }
  }
  
  function focusout() {
    console.log('focusout');
    document.removeEventListener('touchmove', stopMove);
  }
  
  onBeforeRouteLeave(() => {
    focusout();
  })
  
  onBeforeMount(() => {
    focusout();
  })

  return {
    focusin,
    focusout
  }
}